package com.ruoyi.tzzl.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.tzzl.domain.WzAccessRecord;
import com.ruoyi.tzzl.domain.bo.WzFocusonBo;
import com.ruoyi.tzzl.domain.vo.QueryVo;
import com.ruoyi.tzzl.mapper.WzAccessRecordMapper;
import com.ruoyi.tzzl.service.IWzAccessRecordService;
import io.netty.util.internal.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.unit.DataUnit;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * 用户访问记录Service业务层处理
 * @author by caoyong
 * @date 2022/11/18
 **/
@Service
public class WzAccessRecordServiceImpl extends ServiceImpl<WzAccessRecordMapper, WzAccessRecord> implements IWzAccessRecordService {


    @Autowired
    private WzAccessRecordMapper wzAccessRecordMapper;


    /**
     * 添加访问记录
     *
     * @param wzAccessRecord
     */
    @Override
    public boolean access(WzAccessRecord wzAccessRecord) {
        LambdaQueryWrapper<WzAccessRecord> lqw =new LambdaQueryWrapper<>();
        lqw.eq(WzAccessRecord::getWid,wzAccessRecord.getWid());
        lqw.eq(WzAccessRecord::getWatchId,wzAccessRecord.getWatchId());
        WzAccessRecord wzAccessRecord1  = this.getOne(lqw);
        if (ObjectUtils.isEmpty(wzAccessRecord1)){
            wzAccessRecord.setUpdateTime(new Date());
            wzAccessRecord.setCreateTime(new Date());
            return this.save(wzAccessRecord);
        }else {
            wzAccessRecord1.setUpdateTime(new Date());
           return this.updateById(wzAccessRecord1);
        }
    }

    /**
     * 查询访问我的用户信息
     *
     * @param queryVo
     */
    @Override
    public List<WzFocusonBo> userList(QueryVo queryVo) {
        List<WzFocusonBo> list = wzAccessRecordMapper.userList(queryVo);
        return list;
    }
}
